package test1;

import java.util.Random;

public class Role {
    private String name;
    private int blood;
    public Role(){}
    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getBlood() {
        return blood;
    }
    public void setBlood(int blood) {
        this.blood = blood;
    }
    //定义一个方法攻击
    //方法的调用者攻击参数 r1.攻击(r2)
    public void arratck(Role role){
        //随机数生成所造伤害(1-20)
        Random r=new Random();
        int hurt = r.nextInt(20)+1;
        //剩余血量
        int remain= role.getBlood()-hurt;
        if(remain<=0){
            remain=0;
        }
        role.setBlood(remain);
        System.out.println(this.getName()+"踢了"+role.getName()+"一脚"+
                "造成了"+hurt+"点伤害"+role.getName()+"还剩下"+remain);
    }

}
